package otxImporter;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Vector;

import javax.imageio.ImageIO;

public class Main {

	public static void close(String error) {
		out("ERROR: " + error);
		System.exit(0);
	}

	public static void out(String s) {
		System.out.println(s);
	}

	public static void main(String[] args) {
		String filename = "maps/objects copia.png";

		File f = new File(filename);

		if (!f.exists()) {
			close("File \"" + filename + "\" non esistente");
		} else {
			out("File \"" + filename + "\" aperto");
		}

		BufferedImage image = null;

		try {
			image = ImageIO.read(f);
		} catch (IOException e) {
			close(e.toString());
		}

		if (!OTXImporter.isOTX(image)) {
			close("il file specificato non e' nel formato otx");
		}

		out("Apertura file otx");

		OTXImporter importer = new OTXImporter(image);

		Vector<OTXImportable> obj = importer.getObjects();

		out("Oggetti trovati: " + obj.size());

		for (OTXImportable o : obj) {
			out(o.toString());
		}
	}

}
